package com.power.collection;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class MapDemo {
    public static void main(String[] args) {

        Map<Integer, Integer> map = new HashMap<>();
        System.out.println("第一种方式");
        for (int i = 0; i < 10; i++) {
            map.put(i, i);
        }
        //第一种遍历方式
        for (Map.Entry entry : map.entrySet()) {
            System.out.println(entry.getKey() + "  " + entry.getValue());
        }
        System.out.println("第二种方式");
        //第二种方式   key遍历
        for (Integer key : map.keySet()) {
            System.out.println(key);
        }
        //value遍历
        for (Integer value : map.values()) {
            System.out.println(value);
        }
        System.out.println("第三种方式");
        //Iterator的方式遍历
        Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Integer, Integer> entry = (Map.Entry<Integer, Integer>) iterator.next();
            System.out.println(entry.getKey() + "  " + entry.getValue());
        }

        map.forEach((key,value)->{
            System.out.println("key:: "+key+"  "+"value:: "+value);
        });
        MapDemo mapDemo = new MapDemo();
        System.out.println("-------------");
        System.out.println(mapDemo.getObject(1));
    }



    public <T> T getObject( T t){
        return t;
    }
}
